<?php

/**
 *
 * @param array $params
 * @param Smarty_Internal_Template $template
 * @return <type>
 */
function smarty_function_bind($params, $template) {
    $context = ModulesContext::instance();
    $session = $context->getSession();
    
    if ($session->state() == SessionStates::ACTIVE) {
        $name = $params["name"];
        $to = $params["to"];

        $bindings = $session->get("__bindings", array());

        $trueName = $name;
        $squareBracket = strpos($name, "[");
        if($squareBracket !== false){
            $trueName = substr($name, 0, $squareBracket);
        }

        $bindings[$trueName] = $to;
        $session->put("__bindings", $bindings);
    }
    return $name;
}

?>
